<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>

    <title>大象E学</title>
    <!-- head 中 -->
    <link rel="stylesheet" href="../public/css/approval.css"/>
    <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/1.1.2/weui-for-work.css"/>
    <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.0/css/jquery-weui.min.css"/>
    <script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/jquery-weui/1.2.0/js/jquery-weui.min.js"></script>
    <script>
        var isPoneAvailable = function (pone) {
            var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
            if (!myreg.test(pone)) {
                return false;
            } else {
                return true;
            }
        }
        $(function () {
            //点击发送验证码方法
            $("#getCode").on("click", function () {
                if (!isPoneAvailable($("#phone").val())) {
                    $.toast("手机号错误，请重新输入", "text");
                }
                $.ajax({
                    type: "POST",
                    url: "../api/sendMsg",
                    contentType: "application/x-www-form-urlencoded",
                    data: {
                        "phone": $("#phone").val()
                    },
                    success: function (r) {
                        if (r.code === 0) {
                            $.toast("获取验证码成功");
                        } else {
                            $.toast(r.msg, "text");
                        }
                    }
                });
            });
            //点击注册方法
            $("#submit").on("click", function () {
                //校验手机号
                if (!isPoneAvailable($("#phone").val())) {
                    $.toast("手机号错误，请重新输入", "text");
                }
                $.ajax({
                    type: "POST",
                    url: "../api/register",
                    contentType: "application/x-www-form-urlencoded",
                    data: {
                        "phone": $("#phone").val(),
                        "code": $("#code").val()
                    },
                    success: function (r) {
                        if (r.code === 0) {
                            window.location.href = "../api/work.html";
                        } else {
                            $.toast(r.msg, "text");
                        }
                    }
                });
            });
        });
    </script>
</head>
<body ontouchstart="">

<div class="weui-cells weui-cells_form">
    <div class="weui-cell weui-cell_vcode">
        <div class="weui-cell__hd">
            <label class="weui-label">手机号</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="tel" placeholder="请输入手机号" id="phone"/>
        </div>
        <div class="weui-cell__ft">
            <button class="weui-vcode-btn" id="getCode">获取验证码</button>
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">验证码</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="number" placeholder="请输入验证码" id="code"/>
        </div>
    </div>
</div>
<div class="weui-btn-area">
    <a class="weui-btn weui-btn_primary ios-click" href="javascript:" id="submit">验证手机号</a>
</div>
</body>
</html>
